﻿@model AdminQueryViewModel
@using Orchard.ContentManagement;
@inject IContentManager ContentManager

<h1>@RenderTitleSegments(T["Query"])</h1>

<form asp-action="Query" method="get">
    <input asp-for="IndexName" type="hidden" value="@Model.IndexName" />

    <div class="form-group">
        <div class="input-group">
            <input asp-for="Query" type="text" class="form-control" autofocus />
            <span class="input-group-btn">
                <button type="submit" class="btn btn-primary">@T["Query"]</button>
            </span>
        </div>
        <span class="hint">@T["You can use the query <a href=\"{0}\">*:*</a> to search all documents.", Html.Raw(Url.Action("Query", "Admin", new { area = "Lucene", Query = "*:*", IndexName = Model.IndexName }))]</span>
        <span class="hint">@T["See {0} for more examples.", Html.Raw("<a href=\"https://lucene.apache.org/core/4_10_2/queryparser/org/apache/lucene/queryparser/classic/package-summary.html\">https://lucene.apache.org/core/4_10_2/queryparser/org/apache/lucene/queryparser/classic/package-summary.html</a>")]</span>
</div>

    <div class="form-group">
        
    </div>
</form>

<ul class="list-group">
    @foreach (var document in Model.Documents)
    {
        var contentItemId = document.GetField("ContentItemId").StringValue;
        var contentItem = await ContentManager.GetAsync(contentItemId, VersionOptions.Latest);
        
        <li class="list-group-item">
            <a admin-for="@contentItem" />
            
            <div class="float-right">
                <a class="btn btn-primary btn-sm" data-toggle="modal" href="#doc-details-@contentItem.Id" aria-expanded="false" aria-controls="doc-details-@contentItem.Id">
                    @T["Show fields"]
                </a>

                <div class="modal fade" id="doc-details-@contentItem.Id" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-body">
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th>@T["Field name"]</th>
                                            <th>@T["Value"]</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach (var field in document)
                                        {
                                            <tr>
                                                <td><code>@field.Name</code></td>
                                                <td>@field.StringValue</td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </li>
    }
</ul>
